package com.test.test;

import java.util.Arrays;

public class MyList2 implements IList {
	Object[] arry = null;
	private int size;

	public MyList2() {
		arry = new Object[10];
	}

	@Override
	public void add(Object elem) {
		if (size >= 10) {
			int newLen = (arry.length * 3) / 2 + 1;
			arry = Arrays.copyOf(arry, newLen);
		}
		arry[size] = elem;
		size++;
	}

	@Override
	public Object get(int index) {
		if (index >= size) {
			throw new IndexOutOfBoundsException();
		}
		return arry[index];
	}

	@Override
	public int size() {
		return size;
	}

	@Override
	public void clear() {
		for (int i = 0; i < size; i++) {
			arry[i] = null;
		}
		size = 0;
	}

}
